package com.java.main;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import io.swagger.annotations.Api;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

@Configuration
@EnableSwagger2 // 启用 Swagger
public class SwaggerConfig {

	@Bean
	public Docket createRestApi() {
		Docket docket = null;
		// 可以根据配置决定不做任何API生成
		if ("false".equals("true")) {
			docket = new Docket(DocumentationType.SWAGGER_2).apiInfo(new ApiInfo("", "", "", "", "", "", "")).select()
					.apis(RequestHandlerSelectors.none()).build();
		} else {
			docket = new Docket(DocumentationType.SWAGGER_2).apiInfo(apiInfo()).select()
					// 标示只有被 @Api 标注的才能生成API.
					.apis(RequestHandlerSelectors.withClassAnnotation(Api.class)).paths(PathSelectors.any()).build();

		}
		return docket;
	}

	private ApiInfo apiInfo() {
		return new ApiInfoBuilder().title("除过登录接口请求所有数据都需要传hearder头'USER-TOKEN'")// 大标题
				.version("1.0")// 版本
				.build();
	}
}